package ch.prokopovi.db;

import java.nio.ByteBuffer;

public class PureConst {

	public static final String ASSETS_DB_POSTFIX_FORMAT = "000";
	public static final int ASSETS_DB_PARTS_NUMBER = 3;

	// city ids
	public static final int MINSK_ID = 0;
	public static final int GRODNO_ID = 1;
	public static final int BREST_ID = 2;
	public static final int VITEBSK_ID = 3;
	public static final int GOMEL_ID = 4;
	public static final int MOGILEV_ID = 5;

	public static final int BARANOVICHI_ID = 20;
	public static final int BOBRUISK_ID = 21;
	public static final int BORISOV_ID = 22;
	public static final int LIDA_ID = 23;
	public static final int MOZIR_ID = 24;
	public static final int NOVOPOLOCK_ID = 25;
	public static final int ORSHA_ID = 26;
	public static final int PINSK_ID = 27;
	public static final int POLOCK_ID = 28;
	public static final int SOLIGORSK_ID = 29;

	public static final int MOLODZE4NO_ID = 30;
	public static final int SVETLOGORSK_ID = 31;
	public static final int ZLOBIN_ID = 32;
	public static final int RE4ICA_ID = 33;
	public static final int SLUCK_ID = 34;
	public static final int ZODINO_ID = 35;

	public static final int KIEV_ID = 1000;
	public static final int ODESSA_ID = 1001;
	public static final int DONECK_ID = 1002;
	public static final int LVOV_ID = 1003;
	public static final int DNEPROPETROVSK_ID = 1004;

	public static final int CHISINAU_ID = 2000;

	//

	/**
	 * myfin region codes
	 * 
	 * @author public
	 * 
	 */
	public enum MyfinRegion {

		MINSK(1, MINSK_ID), //
		VITEBSK(2, VITEBSK_ID), //
		GOMEL(3, GOMEL_ID), //
		GRODNO(4, GRODNO_ID), //
		BREST(5, BREST_ID), //
		MOGILEV(6, MOGILEV_ID),

		BARANOVICHI(20, BARANOVICHI_ID), //
		BOBRUISK(21, BOBRUISK_ID), //
		BORISOV(22, BORISOV_ID), //
		LIDA(23, LIDA_ID), //
		MOZIR(24, MOZIR_ID), //
		NOVOPOLOCK(25, NOVOPOLOCK_ID), //
		ORSHA(26, ORSHA_ID), //
		PINSK(27, PINSK_ID), //
		POLOCK(28, POLOCK_ID), //
		SOLIGORSK(29, SOLIGORSK_ID), //

		MOLODZE4NO(30, MOLODZE4NO_ID), //
		SVETLOGORSK(31, SVETLOGORSK_ID), //
		ZLOBIN(32, ZLOBIN_ID), //
		RE4ICA(33, RE4ICA_ID), //
		SLUCK(34, SLUCK_ID), //
		ZODINO(35, ZODINO_ID), //

		;

		private final int id;
		private final int masterId;

		private MyfinRegion(int id, int masterId) {
			this.id = id;
			this.masterId = masterId;
		}

		public int getId() {
			return this.id;
		}

		public int getMasterId() {
			return this.masterId;
		}

		public static MyfinRegion get(int masterId) {
			for (MyfinRegion tmp : values()) {
				if (tmp.getMasterId() == masterId) {
					return tmp;
				}
			}
			return null;
		}
	}

	public enum FinanceUaRegion {

		KIEV("7oiylpmiow8iy1smadi", KIEV_ID), //
		ODESSA("7oiylpmiow8iy1smadk", ODESSA_ID), //
		DONECK("7oiylpmiow8iy1smaee", DONECK_ID), //
		LVOV("7oiylpmiow8iy1smadr", LVOV_ID), //
		DNEPROPETROVSK("7oiylpmiow8iy1smadm", DNEPROPETROVSK_ID), //
		;

		private final String uid;
		private final int regionId;

		private FinanceUaRegion(String uid, int masterId) {
			this.uid = uid;
			this.regionId = masterId;
		}

		public static FinanceUaRegion get(String uid) {
			for (FinanceUaRegion tmp : values()) {
				if (tmp.uid.equals(uid)) {
					return tmp;
				}
			}

			return null;
		}

		public static FinanceUaRegion get(int masterId) {
			for (FinanceUaRegion tmp : values()) {
				if (tmp.regionId == masterId) {
					return tmp;
				}
			}
			return null;
		}

		public String getUid() {
			return this.uid;
		}

		public int getRegionId() {
			return this.regionId;
		}
	}

	public static int financeUaPlaceIdTransform(String uid) {
		// final String uidPrefix = "7oiylpmiow8iy1sm";

		byte[] bytes = uid.getBytes();
		int length = bytes.length;

		byte[] b = new byte[4];
		System.arraycopy(bytes, length - 4, b, 0, 4);

		final int id = ByteBuffer.wrap(b).getInt() % 1000000;

		return id;
	}

	public static Integer toPositiveHashCode(String str) {

		return str != null ? Math.abs(str.hashCode()) : null;
	}
}
